﻿using System.ComponentModel;
using CI.Models.Production.Interfaces;

namespace CI.Models.Production
{
    public class IndustryProductionConsumption : ModelBase, IIndustryProductConsumption
    {
        public IndustryProductionConsumption(IIndustryProduct produced, IIndustryProduct consumed)
        {
            _produced = produced;
            _consumed = consumed;
            StartModel();
            UpdateProducedTotal();

            Consumed.Quantity.PropertyChanged += Quantity_PropertyChanged;
        }

        private void Quantity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Total")
            {
                UpdateProducedTotal();
            }
        }

        private void UpdateProducedTotal()
        {
            _produced.Quantity.Total = _consumed.Quantity.Total;
        }


        private readonly IIndustryProduct _produced;
        private readonly IIndustryProduct _consumed;

        public IIndustryProduct Produced
        {
            get { return _produced; }
        }

        public IIndustryProduct Consumed
        {
            get { return _consumed; }
        }
    }
}